package org.itzixi.rabbitmq;


import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {

    public static final String TEST_EXCHANGE = "test_exchange";
    public static final String TEST_QUEUE = "test_queue";
    public static final String ROUTEING_KEY_IMOOC_WECHAT_TEST = "imooc.wechat.test";
    public static final String ROUTEING_KEY_IMOOC_WECHAT_MSG_SEND = "imooc.wechat.msg.send";

    // 创建交换机
    @Bean(TEST_EXCHANGE)
    public Exchange exchange(){
        return ExchangeBuilder.topicExchange(TEST_EXCHANGE).durable(true).build();
    }


    @Bean(TEST_QUEUE)
    public Queue queue(){
        return QueueBuilder.durable(TEST_QUEUE).build();
    }


    @Bean
    public Binding binding(@Qualifier(TEST_EXCHANGE) Exchange exchange, @Qualifier(TEST_QUEUE) Queue queue){
        return BindingBuilder.bind(queue).to(exchange)
                .with("imooc.wechat.#").noargs();
    }



}
